package com.luochen.cdpt.response;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ServiceResponse<T> {

    private String code = "0";

    private String message;

    private T result;

    public static <T> ServiceResponse<T> of(T result) {
        ServiceResponse<T> response = new ServiceResponse<>();
        response.setMessage("调用成功");
        response.setResult(result);
        return response;
    }
    public static <T> ServiceResponse<T> message(String message) {
        ServiceResponse<T> response = new ServiceResponse<>();
        response.setMessage(message);
        response.setResult(null);
        return response;
    }

    public static <T> ServiceResponse<T> error(String message) {
        ServiceResponse<T> response = new ServiceResponse<>();
        response.setMessage(message);
        response.setCode("-1");
        return response;
    }

    public static Map<String, Object> success(String message) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> typeMap = new HashMap<String, Object>();
        typeMap.put("Code", "0");
        typeMap.put("Message", message);
        return map;
    }

    public static Map<String, Object> failure(String message) {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> typeMap = new HashMap<String, Object>();
        typeMap.put("Code", "-1");
        typeMap.put("Message", message);
        return map;
    }

}
